<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>响应式导航栏示例</title>
    <link rel="stylesheet" href="./css/index.css">
</head>

<body>
    <div class="container">
        <nav class="navbar">
            <a href="#" class="nav-brand">TechSite</a>

            <button class="nav-toggle" aria-label="切换导航">
                <span></span>
                <span></span>
                <span></span>
            </button>

            <ul class="nav-menu">
                <li><a href="#home">首页</a></li>
                <li><a href="#about">关于我们</a></li>
                <li><a href="#services">服务项目</a></li>
                <li><a href="#portfolio">作品展示</a></li>
                <li><a href="#contact">联系我们</a></li>
            </ul>
        </nav>

        <div class="content">
            <h1>响应式导航栏演示</h1>
            <p>调整浏览器窗口大小，查看导航栏在不同屏幕尺寸下的表现效果</p>

            <div class="demo-grid">
                <div class="demo-card">
                    <h3>移动端优先</h3>
                    <p>默认隐藏菜单，使用汉堡菜单切换显示</p>
                </div>
                <div class="demo-card">
                    <h3>平板适配</h3>
                    <p>768px以上显示为水平导航，隐藏汉堡菜单</p>
                </div>
                <div class="demo-card">
                    <h3>桌面端优化</h3>
                    <p>1024px以上增加内边距，优化视觉体验</p>
                </div>
            </div>

            <div class="code-section">
                <h3>核心实现代码</h3>
                <pre><code>// JavaScript 交互逻辑
                        const navToggle = document.querySelector('.nav-toggle');
                        const navMenu = document.querySelector('.nav-menu');

                        navToggle.addEventListener('click', () => {
                            navMenu.classList.toggle('active');
                            navToggle.classList.toggle('active');
                        });

                        // 点击菜单外区域关闭菜单
                        document.addEventListener('click', (e) => {
                            if (!e.target.closest('.navbar') && navMenu.classList.contains('active')) {
                                navMenu.classList.remove('active');
                                navToggle.classList.remove('active');
                            }
                        });
                    </code>
                </pre>
            </div>
        </div>
    </div>

    <div class="screen-size" id="screenSize">屏幕尺寸: <span id="sizeInfo"></span></div>

    <script src="./js/index.js"></script>
</body>

</html>